package DALC;

import javax.swing.JOptionPane;
import java.sql.*;

public class ConexaoSQL {
	static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
	static final String DATABASE_URL = "jdbc:mysql://localhost/Supermercado";
	private String sSql;
	private static Connection connection = null;
	private static Statement statement = null;
	public static final int _QUERY = 1;
	public static final int _EXECUTE = 2;
	private static ResultSet resultSet;

	

	public ResultSet getResultSet() {
		return resultSet;

	}

	public ConexaoSQL() {

	}

	public void setSSql(String sql) {
		this.sSql = sql;
	}

	public String getSSql() {
		return sSql;
	}

	public void closeConexao() {
		
			this.sSql = null;
			this.resultSet = null;
			
		
	}

	public ResultSet execute(String sql, int opcao) throws Exception {
		resultSet = null;
		this.sSql = sql;
		Class.forName(JDBC_DRIVER);
		connection = DriverManager.getConnection(DATABASE_URL, "root", "123");
		statement = connection.createStatement();
		switch(opcao){
		case 1: this.resultSet = statement.executeQuery(sSql);
				break;
		case 2: statement.execute(sql);
				break;
		default: 
			break;
		}
		
		return this.resultSet;
	}
}
